home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************************************
- *
- *
- * ObjectMacZapp -- a standard Mac OOP application template
- *
- *
- *
- * ZClipboard.cpp -- the clipboard object
- *
- *
- *
- *
- *
- * © 1997, Graham Cox
- *
- *
- *
- *
- *************************************************************************************************/
-
-
- #include "MacZoop.h"
-
-
- ZClipboard* gClipboard = NULL;
-
-
- /*----------------------------------*** PUTDATA ***-----------------------------------*/
- /*
- put the handle on the clipboard with the type supplied
- ----------------------------------------------------------------------------------------*/
-
- void ZClipboard::PutData( OSType dataType, Handle someData )
- {
- FailNILParam( someData );
-
- long len = GetHandleSize( someData );
- char hs = HGetState( someData );
-
- HLock( someData );
- PutData( dataType, *someData, len );
- HSetState( someData, hs );
- }
-
- /*----------------------------------*** PUTDATA ***-----------------------------------*/
- /*
- put arbitrary data on the clipboard with the type supplied
- ----------------------------------------------------------------------------------------*/
-
- void ZClipboard::PutData( OSType dataType, Ptr dataPtr, const long dataLen )
- {
- Clear();
- AppendData( dataType, dataPtr, dataLen );
-
- SendMessage( clipContentsChanged, (void*) dataType );
- }
-
-
- /*----------------------------------*** PUTDATA ***-----------------------------------*/
- /*
- put the picture on the clipboard with the type 'PICT'
- ----------------------------------------------------------------------------------------*/
-
- void ZClipboard::PutData( PicHandle aPicture )
- {
- PutData( 'PICT', (Handle) aPicture );
- }
-
- /*----------------------------------*** PUTTEXT ***-----------------------------------*/
- /*
- put the text on the clipboard with the type 'TEXT'
- ----------------------------------------------------------------------------------------*/
-
- void ZClipboard::PutText( Handle textH )
- {
- PutData( 'TEXT', textH );
- }
-
- /*----------------------------------*** PUTTEXT ***-----------------------------------*/
- /*
- put the text in an arbitrary buffer on the clipboard with the type 'TEXT'
- ----------------------------------------------------------------------------------------*/
-
- void ZClipboard::PutText( Ptr charBuf, const long textLen )
- {
- Clear();
- AppendText( charBuf, textLen );
- }
-
-
- /*----------------------------------*** APPENDDATA ***--------------------------------*/
- /*
- add the data to the clipboard with the type supplied
- ----------------------------------------------------------------------------------------*/
-
- void ZClipboard::AppendData( OSType dataType, Handle someData )
- {
- FailNILParam( someData );
-
- long len = GetHandleSize( someData );
- char hs = HGetState( someData );
-
- HLock( someData );
- AppendData( dataType, *someData, len );
- HSetState( someData, hs );
-
- SendMessage( clipContentsAppended, (void*) dataType );
- }
-
- /*----------------------------------*** APPENDDATA ***--------------------------------*/
- /*
- add the arbitrary data to the clipboard with the type supplied
- ----------------------------------------------------------------------------------------*/
-
- void ZClipboard::AppendData( OSType dataType, Ptr dataPtr, const long dataLen )
- {
- FailOSErr( PutScrap( dataLen, dataType, dataPtr ));
- }
-
- /*----------------------------------*** APPENDDATA ***--------------------------------*/
- /*
- add the picture to the clipboard with the type 'PICT'
- ----------------------------------------------------------------------------------------*/
-
- void ZClipboard::AppendData( PicHandle aPicture )
- {
- AppendData( 'PICT', (Handle) aPicture );
- }
-
- /*----------------------------------*** APPENDTEXT ***--------------------------------*/
- /*
- add the text to the clipboard with the type 'TEXT'
- ----------------------------------------------------------------------------------------*/
-
- void ZClipboard::AppendText( Handle textH )
- {
- AppendData( 'TEXT', textH );
- }
-
-
- /*----------------------------------*** APPENDTEXT ***--------------------------------*/
- /*
- add the text in an arbitrary buffer to the clipboard with the type 'TEXT'
- ----------------------------------------------------------------------------------------*/
-
- void ZClipboard::AppendText( Ptr charBuf, const long textLen )
- {
- Handle t;
-
- FailOSErr( PtrToHand( charBuf, &t, textLen ));
-
- try
- {
- AppendText( t );
- }
- catch( OSErr err )
- {
- DisposeHandle( t );
-
- throw err;
- }
-
- DisposeHandle( t );
- }
-
- /*-------------------------------------*** CLEAR ***----------------------------------*/
- /*
- make the clipboard empty
- ----------------------------------------------------------------------------------------*/
-
- void ZClipboard::Clear()
- {
- FailOSErr( ZeroScrap());
-
- SendMessage( clipContentsCleared, NULL );
- }
-
- /*------------------------------------*** GETDATA ***---------------------------------*/
- /*
- get the data from the clipboard with the type requested
- ----------------------------------------------------------------------------------------*/
-
- Handle ZClipboard::GetData( OSType dataType )
- {
- Handle h = NULL;
- long result, offset;
-
- if ( QueryType( dataType ))
- {
- FailNIL( h = NewHandle( 0 ));
-
- result = GetScrap( h, dataType, &offset);
-
- if (result <= 0)
- {
- DisposeHandle( h );
- FailOSErr( noTypeErr );
- }
- }
-
- return h;
- }
-
-
- /*----------------------------------*** QUERYTYPE ***---------------------------------*/
- /*
- does the clipboard have this data type?
- ----------------------------------------------------------------------------------------*/
-
- Boolean ZClipboard::QueryType( OSType dataType )
- {
- long result, offset;
-
- result = GetScrap( NULL, dataType, &offset );
-
- return ( result > 0 );
- }
-
- /*----------------------------------*** GETDATASIZE ***-------------------------------*/
- /*
- how big is the data of this type?
- ----------------------------------------------------------------------------------------*/
-
- long ZClipboard::GetDataSize( OSType dataType )
- {
- long result, offset;
-
- result = GetScrap( NULL, dataType, &offset );
-
- if ( result > 0 )
- return result;
- else
- return -1;
- }
-
- /*--------------------------------*** GETCLIPSTATUS ***-------------------------------*/
- /*
- what state is the clipboard in?
- ----------------------------------------------------------------------------------------*/
-
- short ZClipboard::GetClipStatus()
- {
- PScrapStuff ps;
-
- ps = InfoScrap();
-
- return ps->scrapCount;
- }
-
-